package com.shuoyue.ycgk.ui.recruitment;

import com.shuoyue.ycgk.base.BasePresenter;
import com.shuoyue.ycgk.base.BaseResult;
import com.shuoyue.ycgk.base.BaseView;
import com.shuoyue.ycgk.base.ListWithPage;
import com.shuoyue.ycgk.base.baseadapter.AppBaseQuickAdapter;
import com.shuoyue.ycgk.entity.JobHis;
import com.shuoyue.ycgk.entity.JobInfo;
import com.shuoyue.ycgk.entity.RecruitmentItem;
import com.shuoyue.ycgk.entity.RecruitmentItemHis;
import com.shuoyue.ycgk.net.RetrofitClient;
import com.shuoyue.ycgk.net.base.ApiSubscriber;
import com.shuoyue.ycgk.net.gsondefaultadapter.Optional;

import io.reactivex.Observable;

public interface FocusNoticeListContact {
    interface View extends BaseView {

        void setFocuseNotice(ListWithPage<RecruitmentItem> list);

        void setFocuseJob(ListWithPage<JobInfo> list);

        void setHisNotice(ListWithPage<RecruitmentItemHis> list);

        void setHisJob(ListWithPage<JobHis> list);

        void deleteHis(AppBaseQuickAdapter adapter, Object o);

    }

    class Presenter extends BasePresenter<View> {
        Model model = new Model();

        public void getRecFocuse(int page) {
            apply(model.getFocusRecruiment(page))
                    .subscribe(new ApiSubscriber<Optional<ListWithPage<RecruitmentItem>>>(mView, this) {
                        @Override
                        public void onNext(Optional<ListWithPage<RecruitmentItem>> data) {
                            super.onNext(data);
                            mView.setFocuseNotice(data.getIncludeNull());
                        }
                    });
        }

        public void getJobFocuse(int page) {
            apply(model.getFocusJob(page))
                    .subscribe(new ApiSubscriber<Optional<ListWithPage<JobInfo>>>(mView, this) {
                        @Override
                        public void onNext(Optional<ListWithPage<JobInfo>> data) {
                            super.onNext(data);
                            mView.setFocuseJob(data.getIncludeNull());
                        }
                    });
        }

        public void getHisRecruiment(int page) {
            apply(model.getHisRecruiment(page))
                    .subscribe(new ApiSubscriber<Optional<ListWithPage<RecruitmentItemHis>>>(mView, this) {
                        @Override
                        public void onNext(Optional<ListWithPage<RecruitmentItemHis>> data) {
                            super.onNext(data);
                            mView.setHisNotice(data.getIncludeNull());
                        }
                    });
        }

        public void getHisJob(int page) {
            apply(model.getHisJob(page))
                    .subscribe(new ApiSubscriber<Optional<ListWithPage<JobHis>>>(mView, this) {
                        @Override
                        public void onNext(Optional<ListWithPage<JobHis>> data) {
                            super.onNext(data);
                            mView.setHisJob(data.getIncludeNull());
                        }
                    });
        }

        public void deleteHis(AppBaseQuickAdapter adapter, Object o, int id) {
            apply(model.deleteHis(id))
                    .subscribe(new ApiSubscriber<Optional<ListWithPage<JobHis>>>(mView, this) {
                        @Override
                        public void onNext(Optional<ListWithPage<JobHis>> data) {
                            super.onNext(data);
                            mView.deleteHis(adapter,o);
                        }
                    });
        }

    }

    class Model {

        public Observable<BaseResult<ListWithPage<RecruitmentItem>>> getFocusRecruiment(int page) {
            return RetrofitClient.getInstance().getApi().getFocusRecruiment(2, 1, page);
        }

        public Observable<BaseResult<ListWithPage<JobInfo>>> getFocusJob(int page) {
            return RetrofitClient.getInstance().getApi().getFocusJob(2, 2, page);
        }

        public Observable<BaseResult<ListWithPage<RecruitmentItemHis>>> getHisRecruiment(int page) {
            return RetrofitClient.getInstance().getApi().getHisRecruiment(1, 1, page);
        }

        public Observable<BaseResult<ListWithPage<JobHis>>> getHisJob(int page) {
            return RetrofitClient.getInstance().getApi().getHisJob(1, 2, page);
        }

        public Observable<BaseResult<ListWithPage<JobHis>>> deleteHis(int id) {
            return RetrofitClient.getInstance().getApi().deleteHis(id);
        }
    }
}
